#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<queue>
using namespace std;
int r, c;
char pct[41][41] = { '\0' };
int dx[] = { 0,0,1,-1 }, dy[] = { 1,-1,0,0 };
int vis[41][41] = { 0 };
struct point {
	int x; int y;
	point(int x = 0, int y = 0) {
		this->x = x; this->y = y;
	}
};
point route[41][41] = { {0,0} };

void bfs(int sx, int sy) {
	queue<point>q;
	q.push({ sx,sy });
	vis[sx][sy] = 1;
	route[sx][sy].x = -1;
	route[sx][sy].y = -1;

	while (q.size()) {
		for (int i = 0; i < 4; i++) {
			int nx = q.front().x + dx[i], 
				ny = q.front().y + dy[i];
			if (nx < 0 || nx >= r)
				continue;
			if (ny < 0 || ny >= c)
				continue;
			if (vis[nx][ny] == 1)
				continue;
			if (pct[nx][ny] == '#')
				continue;
			route[nx][ny].x=q.front().x;
			route[nx][ny].y=q.front().y;
			//cout << nx << ' ' << ny<< '_' << q.front().x <<'_'<< q.front().y << endl;
			vis[nx][ny] = 1;
			if (nx == r - 1 && ny == c - 1) {
				return;
			}
			q.push({ nx,ny });
		}
		q.pop();
	}

}

/*
5 5
..###
#....
#.#.#
#.#.#
#.#..
0 1_0_0
1 1_0_1
1 2_1_1
2 1_1_1
1 3_1_2
3 1_2_1
1 4_1_3
2 3_1_3
4 1_3_1
3 3_2_3
4 3_3_3
4 4_4_3
7
*/

int main()
{
	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> pct[i][j];
		}
	}
	bfs(0, 0);
	int step = 0;
	int fx = r - 1, fy = c - 1;
	//cout << fx << ' ' << fy << endl;
	while (fx!= -1 && fy != -1) {
		int tx = fx, ty = fy;
		fx = route[tx][ty].x;
		fy = route[tx][ty].y;
		//cout << fx << ' ' << fy << endl;
		step++;
	}
	cout << step;
	return 0;
}
